import { combineReducers } from 'redux';

// imports all file except index.js
const req = require.context('.', true, /^(?!.\/index)(?!.\/__tests__).*.js$/);

const modules = {};
const sagas = [];

req.keys().forEach((key) => {
  const regex = /.\/(.*?).js$/;
  const moduleName = regex.test(key) && key.match(regex)[1];

  const { reducers, effects } = req(key).default;
  modules[moduleName] = reducers;
  sagas.push(effects);
});

export default { reducers: combineReducers(modules), sagas };
